package com.yanqu.road.server.cmd.activity.lanyamemorial;

import com.yanqu.road.entity.activity.langyamemorial.LangYaMemorialUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaMemorialProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.langyamemorial.LangYaMemorialActivityPb;
import com.yanqu.road.server.gameplayer.module.activity.langyamemorial.LangYaMemorialModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.langyamemorial.LangYaMemorialMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_LANGYA_MEMORIAL_GET_USER_DATA, desc = "获取玩家数据")
public class LangYaMemorialGetUserCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        if (!ActivityMgr.activityInShowTime(LangYaMemorialMgr.getActivityInfo()) || LangYaMemorialMgr.getConfig() == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        LangYaMemorialUserData userData = player.getModule(LangYaMemorialModule.class).getUserData();
        if(userData == null){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        LangYaMemorialProto.LangYaMemorialGetUserDataRespMsg.Builder builder = LangYaMemorialProto.LangYaMemorialGetUserDataRespMsg.newBuilder().setRet(ret);
        builder.setUserData(LangYaMemorialActivityPb.buildUserData(userData));
        player.sendPacket(Protocol.U_LANGYA_MEMORIAL_GET_USER_DATA, builder);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_LANGYA_MEMORIAL_GET_USER_DATA, LangYaMemorialProto.LangYaMemorialGetUserDataRespMsg.newBuilder().setRet(ret));
        }
    }
}
